package com.currency.controller.exe;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.currency.exception.AppException;
import com.currency.response.BaseResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionHandleController {
    private static final Log log = LogFactory.get(ExceptionHandleController.class);

    @ExceptionHandler(AppException.class)
    public @ResponseBody
    BaseResponse handleAppException(AppException e) {
        return new BaseResponse(e.getErrCode(), e.getErrMsg());
    }

    @ExceptionHandler(Exception.class)
    public @ResponseBody
    BaseResponse handleException(Exception e) {
        e.printStackTrace();
        log.info(e.getLocalizedMessage());
        return new BaseResponse("cey9999", "系统开小差，请稍后再试");
    }
}
